using Newtonsoft.Json;
using LiJ.Common.Core;
using LiJ.Http.Mos;
using LiJ.Framework.Official.Shake.Mos;
using System.Threading.Tasks;

namespace LiJ.Framework.Official.Shake
{
	/// <summary>
	/// 微信的摇一摇接口
	/// </summary>
	/// <summary>
	///   微信摇一摇红包接口
	/// </summary>
	public class WxOffShakeApi : WxOffBaseApi
	{
		/// <summary>
		///
		/// </summary>
		/// <param name="config">配置信息，如果这里不传，需要在程序入口静态 WxBaseApi.DefaultConfig 属性赋值</param>
		public WxOffShakeApi(AppConfig config = null)
			: base(config)
		{
		}

		static WxOffShakeApi()
		{
		}

		/// <summary>
		/// 创建红包活动
		/// </summary>
		/// <param name="userTemplate">是否使用模板，1：使用，2：不使用,以参数的形式拼装在url后。（模版即交互流程图中的红包加载页，使用模板用户不需要点击可自动打开红包；不使用模版需自行开发HTML5页面，并在页面调用红包jsapi）</param>
		/// <param name="logUrl">使用模板页面的logo_url，不使用模板时可不加。展示在摇一摇界面的消息图标。图片尺寸为120x120</param>
		/// <param name="lotteryReq">活动对应内容</param>
		/// <returns></returns>
		public async Task<WxAddLotteryResp> AddLottery(int userTemplate, string logUrl, WxAddLotteryReq lotteryReq)
		{
			LHttpRequest req = new LHttpRequest
			{
				HttpMothed = HttpMothed.Post,
				AddressUrl = "https://api.weixin.qq.com" + string.Format("/shakearound/lottery/addlotteryinfo?use_template={0}&logo_url={1}", userTemplate, logUrl),
				CustomBody = JsonConvert.SerializeObject(lotteryReq)
			};
			return await base.RestCommonOffcialAsync<WxAddLotteryResp>(req, null);
		}

		/// <summary>
		///   录入红包信息
		/// </summary>
		/// <param name="prizeReq">红包内容</param>
		/// <returns></returns>
		public async Task<WxSetLotteryPrizeResp> SetLotteryPrize(WxSetLotteryPrizeReq prizeReq)
		{
			LHttpRequest req = new LHttpRequest
			{
				HttpMothed = HttpMothed.Post,
				AddressUrl = "https://api.weixin.qq.com" + "/shakearound/lottery/setprizebucket",
				CustomBody = JsonConvert.SerializeObject(prizeReq)
			};
			return await base.RestCommonOffcialAsync<WxSetLotteryPrizeResp>(req, null);
		}

		/// <summary>
		/// 设置红包活动抽奖开关
		/// </summary>
		/// <param name="lotteryId">红包抽奖id，来自addlotteryinfo返回的lottery_id</param>
		/// <param name="onoff">活动抽奖开关，0：关闭，1：开启</param>
		/// <returns></returns>
		public async Task<WxBaseResp> SetLotterySwitch(string lotteryId, int onoff)
		{
			LHttpRequest req = new LHttpRequest
			{
				HttpMothed = HttpMothed.Get,
				AddressUrl = "https://api.weixin.qq.com" + string.Format("/shakearound/lottery/setlotteryswitch?lottery_id={0}&onoff={1}", lotteryId, onoff)
			};
			return await base.RestCommonOffcialAsync<WxBaseResp>(req, null);
		}

		/// <summary>
		/// 查询红包信息
		/// </summary>
		/// <param name="lotteryId">红包抽奖id，来自addlotteryinfo返回的lottery_id</param>
		/// <returns></returns>
		public async Task<WxGetLotteryResp> GetLotterySwitch(string lotteryId)
		{
			LHttpRequest req = new LHttpRequest
			{
				HttpMothed = HttpMothed.Get,
				AddressUrl = "https://api.weixin.qq.com" + "/shakearound/lottery/querylottery?lottery_id=" + lotteryId
			};
			return await base.RestCommonOffcialAsync<WxGetLotteryResp>(req, null);
		}
	}
}
